using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class JcHistMap : EntityTypeConfiguration<JcHist>
    {
        public JcHistMap()
        {
            // Primary Key
            this.HasKey(t => new { t.id, t.PERIOD, t.BATCH, t.ACCT, t.CURRENCY, t.JOBID });

            // Properties
            this.Property(t => t.id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.PERIOD)
                .IsRequired()
                .HasMaxLength(4);

            this.Property(t => t.BATCH)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.DESC)
                .HasMaxLength(40);

            this.Property(t => t.ACCT)
                .IsRequired()
                .HasMaxLength(40);

            this.Property(t => t.CURRENCY)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            this.Property(t => t.JOBID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("JcHist");
            this.Property(t => t.id).HasColumnName("id");
            this.Property(t => t.DATE).HasColumnName("DATE");
            this.Property(t => t.DEBIT).HasColumnName("DEBIT");
            this.Property(t => t.CREDIT).HasColumnName("CREDIT");
            this.Property(t => t.PERIOD).HasColumnName("PERIOD");
            this.Property(t => t.BATCH).HasColumnName("BATCH");
            this.Property(t => t.DESC).HasColumnName("DESC");
            this.Property(t => t.ACCT).HasColumnName("ACCT");
            this.Property(t => t.DEBITDOL).HasColumnName("DEBITDOL");
            this.Property(t => t.CREDITDOL).HasColumnName("CREDITDOL");
            this.Property(t => t.CURRENCY).HasColumnName("CURRENCY");
            this.Property(t => t.DEBITACCT).HasColumnName("DEBITACCT");
            this.Property(t => t.CREDITACCT).HasColumnName("CREDITACCT");
            this.Property(t => t.CSTCTRID).HasColumnName("CSTCTRID");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.JOBID).HasColumnName("JOBID");

            // Relationships
            this.HasRequired(t => t.Acct1)
                .WithMany(t => t.JcHists)
                .HasForeignKey(d => d.ACCT);

        }
    }
}
